<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small"  v-show="showSearch" label-width="68px">
      <el-form-item label="城市等级" prop="city" >
        <el-select v-model="queryParams" placeholder="请选择活动区域">
          <el-option label="一线城市" value="一线城市"></el-option>
          <el-option label="二线城市" value="二线城市"></el-option>
          <el-option label="三线城市" value="三线城市"></el-option>
          <el-option label="全部" value="全部"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="城市" prop="city" >
        <el-select v-model="queryParams.city" placeholder="请选择活动区域">
          <el-option
            v-for="item in showdept"
            :key="item.city"
            :label="item.city"
            :value="item.city">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="行政区" prop="registrationTime">

      </el-form-item>
      <el-form-item label="车辆类型" prop="registrationTime">
        <el-radio-group v-model="queryParams.documentsstatus">
          <el-radio :label="1" >经济</el-radio>
          <el-radio :label="2" >舒适</el-radio>
          <el-radio :label="3" >豪华</el-radio>
          <el-radio :label="4" >货运</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="能源类型" prop="registrationTime">
        <el-radio-group v-model="queryParams.energyType">
          <el-radio label="纯电" >纯电</el-radio>
          <el-radio label="燃油" >燃油</el-radio>
          <el-radio label="混动" >混动</el-radio>

        </el-radio-group>
      </el-form-item>
      <el-form-item label="审核人" prop="registrationTime">
        <el-input v-model="queryParams. us" placeholder="请输入审核人" >
        </el-input>
      </el-form-item>
      <el-form-item label="注册时间">
        <el-col :span="11">
          <el-date-picker type="date" placeholder="选择日期" v-model="queryParams.registration1" style="width: 100%;"></el-date-picker>
        </el-col>
        <el-col class="line" :span="2">-</el-col>
        <el-col :span="11">
          <el-date-picker placeholder="选择时间" v-model="queryParams.registration2" style="width: 100%;"></el-date-picker>
        </el-col>
      </el-form-item>
      <el-form-item label="审核状态" prop="registrationTime">
        <el-radio-group v-model="queryParams.carstatus">
          <el-radio :label="0" >未通过</el-radio>
          <el-radio :label="1" >已通过</el-radio>
          <el-radio :label="2" >待审核</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="" prop="registrationTime">
        <el-input v-model="queryParams.mohu" placeholder="请输入姓名，手机号，车牌号查询" >
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:vehicle:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:vehicle:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:vehicle:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:vehicle:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="vehicleList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="主键" align="center" prop="id"/>
      <el-table-column label="车辆类型" align="center" prop="vechicleType">
        <template slot-scope="scope">
          {{ scope.row.vechicleType==1?"经济型":"舒适型" }}
        </template>
      </el-table-column>

      <el-table-column label="车牌号" align="center" prop="licensePlateNumber"/>
      <el-table-column label="车型" align="center" prop="vehicleModel"/>
      <el-table-column label="能源类型" align="center" prop="energyType"/>
      <el-table-column label="品牌" align="center" prop="brand"/>
      <el-table-column label="厂家" align="center" prop="factory"/>
      <el-table-column label="车龄" align="center" prop="cheage"/>
      <el-table-column label="车辆VIN编号" align="center" prop="vinNumber"/>
      <el-table-column label="发动机编号" align="center" prop="engineNumber"/>
      <el-table-column label="司机姓名" align="center" prop="name"/>
      <el-table-column label="司机手机号" align="center" prop="tel"/>
      <el-table-column label="司机注册时所在城市" align="center" prop="city"/>

      <el-table-column label="注册时间" align="center" prop="registration"/>
      <el-table-column label="提交审核时间" align="center" prop="submissiontime"/>
      <el-table-column label="审核通过时间" align="center" prop="approved"/>
      <el-table-column label="审核状态" align="center" prop="carstatus" fixed="right"/>
      <el-table-column label="审核人" align="center" prop="" fixed="right"/>
      <el-table-column label="操作" fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-upload"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:vehicle:remove']"
          >详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!--    详情对话框-->
    <el-dialog title="司机及车辆详情" :visible.sync="open" width="1000px" append-to-body>
      <div style="font-size: max(15px, 1vw)">司机信息</div>
      <el-container >
        <el-aside class="el-aside1">
            <image-preview :src="form.photo" :width="250" :height="300"/>
        </el-aside>
        <el-main>
          <el-descriptions size="medium" :title="form.name" direction="horizontal">
            <el-descriptions-item label="性别">{{form.sex==1?"男":"女"}}</el-descriptions-item>
            <el-descriptions-item label="生日">{{form.age}}</el-descriptions-item>
            <el-descriptions-item label="年龄">{{form.age}}</el-descriptions-item>
            <br>
            <el-descriptions-item label="手机号">{{form.tel}}</el-descriptions-item>
            <el-descriptions-item label="邮箱">{{form.mailbox}}</el-descriptions-item>
            <el-descriptions-item label="驾照有效期">{{form.validity}}</el-descriptions-item>
            <br>
            <el-descriptions-item label="城市">{{form.city}}</el-descriptions-item>
            <el-descriptions-item label="行政区">{{form.administrativeDistrict}}</el-descriptions-item>
            <el-descriptions-item label="注册时间">{{ form.registration }}</el-descriptions-item>
          </el-descriptions>
        </el-main>
      </el-container>
      <div style="font-size: max(15px, 1vw)">车辆信息</div>
      <el-container >
        <el-aside class="el-aside2" width="500px">
          <image-preview :src="form.picturesimage" :width="450" :height="400"/>
        </el-aside>
        <el-main>
          <el-descriptions size="medium" title="" >
            <el-descriptions-item label="车辆类型：">{{form.vechicleType==1?"经济型":"舒适型" }}</el-descriptions-item>
            <el-descriptions-item label="车牌号：">{{form.licensePlateNumber }}</el-descriptions-item>
            <el-descriptions-item label="车型：">{{form.vehicleModel }}</el-descriptions-item>
            <el-descriptions-item label="品牌">{{form.brand }}</el-descriptions-item>
            <el-descriptions-item label="厂家">{{form.factory }}</el-descriptions-item>
            <el-descriptions-item label="能源类型">{{form.energyType }}</el-descriptions-item>
            <el-descriptions-item label="发动机号/电动机号">{{form.engineNumber }}</el-descriptions-item>
            <el-descriptions-item label="车辆VIN码">{{form.vinNumber }}</el-descriptions-item>
            <el-descriptions-item label="电池容量(KWH)">{{form.batterycapacity  }}</el-descriptions-item>
            <el-descriptions-item label="车龄">{{form.cheage}}</el-descriptions-item>
            <el-descriptions-item label="CLTC续航里程">{{form.endurance  }}</el-descriptions-item>
            <el-descriptions-item label="电池类型">{{form.batterytype  }}</el-descriptions-item>
          </el-descriptions>
        </el-main>
      </el-container>

      <div style="font-size: max(15px, 1vw)">审核信息</div>
      <el-container >
        <el-aside class="el-aside1" width="220px">
          <image-preview :src="form.driveimg" :width="170" :height="300"/>
        </el-aside>
        <el-aside class="el-aside1" width="220px">
          <image-preview :src="form.steerimg" :width="170" :height="300"/>
        </el-aside>
        <el-aside class="el-aside1" width="220px">
          <image-preview :src="form.inspectimg" :width="170" :height="300"/>
        </el-aside>
        <el-main>
          <el-descriptions size="medium" title="" direction="vertical" >
            <el-descriptions-item label="提交审核对象：">{{ }}</el-descriptions-item>
            <el-descriptions-item label="审核状态：">{{ form.carstatus}}</el-descriptions-item>
            <el-descriptions-item label="审核通过时间：">{{form.approved }}</el-descriptions-item>
            <el-descriptions-item label="审核人">{{ }}</el-descriptions-item>
          </el-descriptions>
        </el-main>
      </el-container>

    </el-dialog>

  </div>
</template>

<script>
import { listVehicle, getVehicle, delVehicle, addVehicle, updateVehicle } from '@/api/system/vehicle'
import { citysel } from '@/api/cityRank/cityRank'

export default {
  name: 'Vehicle',
  data() {
    return {
      showdept: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 车辆信息
      vehicleList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getList()
    this.getList1()
  },
  methods: {
    /** 查询车辆信息
     列表 */
    getList() {
      this.loading = true
      listVehicle(this.queryParams).then(response => {
        this.vehicleList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    getList1() {
      citysel().then(res=>{
        this.showdept = res.data
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {}
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加车辆信息'
    },

    /** 详情按钮操作 */
    handleDelete(row) {
      this.open = true
      this.form = row
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/vehicle/export', {
        ...this.queryParams
      }, `vehicle_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
<style>
.el-aside1 {
  text-align: left;
  line-height: 90px;
}
.el-aside2 {
  text-align: left;
  line-height: 50px;
}
.el-main {

  line-height: 160px;
}
</style>
